﻿Imports ImageProcessor


Public Class frmDifferenceViewer

    Dim fd As New FrameDifference

    Private Sub cmdBrowseFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBrowseFirst.Click
        ofdFirst.ShowDialog()
    End Sub

    Private Sub ofdFirst_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ofdFirst.FileOk
        txtFirst.Text = ofdFirst.FileName
    End Sub

    Private Sub cmdBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBrowse.Click
        ofdSecond.ShowDialog()
    End Sub

    Private Sub ofdSecond_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ofdSecond.FileOk
        txtSecond.Text = ofdSecond.FileName

    End Sub

    Private Sub cmdProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdProcess.Click
        If txtFirst.Text = "" Then
            MsgBox("Please specify the first image file", MsgBoxStyle.Critical, "Unespecified file")
        ElseIf txtSecond.Text = "" Then
            MsgBox("Please specify the second image file", MsgBoxStyle.Critical, "Unespecified file")
        Else
            process()
        End If


    End Sub

    Private Sub process()
        fd.Threshold = Integer.Parse(nupThreshold.Value)
        fd.SetBaseFrame(txtFirst.Text)
        pbResult.Image = fd.Apply(txtSecond.Text)
        fd.Reset()

    End Sub

    Private Sub nupThreshold_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nupThreshold.ValueChanged
        process()

    End Sub
End Class
